#sing @echo off & SetLocal EnableDelayedExpansion & del "#pathlog.txt" & #newl cd /d "#ppthapps\mencoder"
#newl#sing set max=512|#newl#sing set max=480|--Fallback width. There is no space at the end.--
#newl set audionew=-acodec mp2 -ab 128k|#newl set audionew=-acodec libmp3lame -ab 128k|#newl set audionew=-acodec mp2 -ab 64k -ac 1|--Fallback audio codec--
#newl FOR /F "tokens=1,2 delims==" %%G IN ('mplayer.exe -identify -frames 0 -vo null -ao null  "#item" ') DO ( 
#newl IF %%G==ID_AUDIO_FORMAT IF %%H==85 (set encodemp3=-acodec copy& set audio_codec=%%H) else (set encodemp3=!audionew!& set audio_codec=not_mp3)  )
#newl set /a newheight=(!max!*!ID_VIDEO_HEIGHT!)/!ID_VIDEO_WIDTH!
#newl set /a checkeven=!newheight!/2*2 & if not !checkeven!==!newheight! set /a newheight=!newheight!+1 
#newl if !ID_VIDEO_WIDTH! leq !max!  (set resizeline=) else (set resizeline=-s !max!:!newheight!)
#newl echo old size="!ID_VIDEO_WIDTH!:!ID_VIDEO_HEIGHT!" new size="!max!:!newheight!",  audio_codec="!audio_codec!" & echo *** resizeline="!resizeline!" encodemp3="!encodemp3!"
#newl "#ppthapps\ffmpeg\ffmpeg.exe" |-program file-
-i "#item" |-i "#item" -i "#path#name.mp2" |-i "#item" -i "#path#name.mp3" |-i "#item" -i "#path#name.aac" |-i "#item" -i "#path#name.wav" |-i "#item" -i "#path#name.mpa" |-i "#item" -r 1 -loop_input -i "d:\picture.jpg" -shortest |-input, or encode with alternate audio source file-
-vcodec mpeg4 -q:v 3.3 |-vcodec mpeg4 -b 500k |-vcodec mpeg4 -b 1000k |-vcodec libxvid -b 1000k |-vcodec libxvid -q:v 3.3 |-vcodec copy |
!resizeline! |-s 512x384 |-s 480x270 |-s 320x240 |-s 640x480 |-resize, !! means use (resulting) variable-
#remark -scaling type-|-sws_flags fast_bilinear |--scaling type--
!encodemp3! |-acodec mp2 -ab 128k |-acodec mp2 -ab 64k -ac 1 |-acodec mp2 -ab 128k |-acodec libmp3lame  -ab 64k -ac 1 |-acodec libmp3lame -ab 128k |-acodec copy |-acodec pcm_s16le |-acodec aac -strict experimental |-acodec libvorbis |-an |--Audio codec. Use mkv or mp4 as output when using aac.--|--!! means use (resulting) variable--
-vtag XVID -threads 2 |-vtag DIVX |-vtag H264 |-vtag AVC1 |-Video tag-
#remark -start time-|-ss 00:02:40 |-Start time. Optional. HH:MM:SS-
#remark -endtime-|-t 10 |-t 5 |-vframes 250 |-endtime-
#remark -overwrite existing file-|-y |-overwrite existing file-
"#path#name-ffm.avi" |"#path#name-ffm.mkv" |"#path#name-ffm.mp4" |-output-
#newl set oldLength=!ID_LENGTH!
#newl FOR /F "tokens=1,2 delims==" %%G IN ('mplayer.exe -identify -frames 0 -vo null -ao null  "#path#name-ffm.avi" ') DO ( set %%G=%%H)
#newl set newLength=!ID_LENGTH!& echo old length:!oldLength!, new length:!newLength!.
#newl IF !newLength!==!oldLength! (echo old length:!oldLength!, new length:!newLength! "#item" resizeline="!resizeline!" encodemp3="!encodemp3!" >> "#pathlog.txt") ELSE (echo WARNING: old length:!oldLength!, new length:!newLength! "#item" resizeline="!resizeline!" encodemp3="!encodemp3!">> "#pathlog.txt")


<comment>
Resize width if greater than 512. If not in mp3, encode audio to mp2.
Write down length of source and destination video to log.txt
This one uses ffmpeg for encoding. Slower, but more reliable. 
Auto calc of height is not always perfect. Does not work with rmvb files.